varying vec4 diffuseCol, ambientCol,ambientGlobal;
varying vec3 normal, lightDir, halfVector;
varying float dist;


void main(){

	vec3 n, halfV, viewV,ldir;
	float NdotL, NdotHV;
	
	vec4 color = ambientGlobal;
	float att;
	
	n = normalize(normal);	//varying normal cannot be written in fragment/pixel shader, so use new variable
	
	NdotL = max(dot(n,lightDir),0.0);		//sin of Normal and Lightdir
	
	//specular component, only if NdotL is 
	if(NdotL > 0){
	
		att = 1.0 / (gl_LightSource[0].constantAttenuation +
					gl_LightSource[0].linearAttenuation * dist +
					gl_LightSource[0].quadraticAttenuation * dist * dist);

	
		color = color + att*(diffuseCol * NdotL + ambientCol);
		halfV = normalize(halfVector); //also knockout varying ;)
		NdotHV = max(dot(n,halfV),0.0);
		//spec same as perVertexLighting
		color = color + gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV, gl_FrontMaterial.shininess);
	}

	
	gl_FragColor = color;	//use here calculated color instead of fixed calculated one
}